In Kotlin, ==
is used to compare the content of two objects, returning true
if their content is equal. Three equals signs (===
) is used for instance equality,
returning true if both references point to the same actual underlying Kotlin object.
If you run this example here in the Klassbook, you will see both lines
print true
. You get true
for the first line and false
for the second line
when running in Kotlin/JVM. The discrepancy has to do with the way Kotlin
“transpiles” its code into JavaScript and the way that JavaScript compares
strings, as is outlined in this Stack Overflow answer.
You can learn more about this in:
Tags: